package com.heima.article.listen;

import com.heima.common.article.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 用于将监听到的行为数据
 * 存入到redis队列中 等待计算
 **/
@Component
@Slf4j
public class HotArticleScoreListener {
    @Autowired
    StringRedisTemplate redisTemplate;

    @RabbitListener(queuesToDeclare = @Queue(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE))
    public void handleHotArticleBehaviorMsg(String behaviorJson) {
        log.info("接收到新增行为消息 消息内容：{}", behaviorJson);
        redisTemplate.opsForList().rightPush(
                HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_LIST,
                behaviorJson
        );
    }
}